package game.data;

class CDData {
	/**
	 * CD数据
	 */
	public var cdNames:Map<String, CDChildData> = [];

	public function new() {}

	/**
	 * 设置CD
	 * @param name 
	 * @param time 
	 */
	public function setCD(name:String, time:Float):Void {
		if (cdNames[name] != null) {
			cdNames[name].cd = time;
		} else {
			cdNames[name] = {
				cd: time
			};
		}
	}

	/**
	 * 是否处于CD中
	 * @param name 
	 * @return Bool
	 */
	public function isCDing(name:String):Bool {
		return cdNames.exists(name) && cdNames[name].cd > 0;
	}

	/**
	 * 清空所有CD
	 */
	public function clearAll():Void {
		cdNames = [];
	}

	/**
	 * 更新CD
	 * @param dt 
	 */
	private function update(dt:Float):Void {
		for (key => value in cdNames) {
			cdNames[key].cd = value.cd - dt;
			if (cdNames[key].cd <= 0) {
				cdNames.remove(key);
			}
		}
	}
}

typedef CDChildData = {
	cd:Float
}
